import time
from unittest import TestCase
from appium import webdriver
from LoanData import LoanData
from LoanOperation import LoanOperation
from ddt import ddt, data, unpack


@ddt
class TestQuota(TestCase):
    loan_data = LoanData()
    url = 'http://127.0.0.1:4723/wd/hub'
    param = {
        "deviceName": "8HJ76H49KJQKM7IF",
        "platformName": "Android",
        "platformVersion": "13",
        "appPackage": "com.duxiaoman.wallet",
        "appActivity": "com.duxiaoman.wallet.home.SplashActivity"
    }

    @data(*loan_data.loan_data)
    @unpack
    def test_quota(self, loan_amount, loan_term, repayment_way, card, pwd, expect):
        time.sleep(5)
        driver = webdriver.Remote(self.url, self.param)
        loan_operation = LoanOperation()
        result = loan_operation.loan(driver, loan_amount, loan_term, repayment_way, card, pwd)
        if result != expect:
            driver.save_screenshot('借款失败！' + '.jpg')
        else:
            print('通过')
        self.assertEqual(result, expect)
